package com.woniuxy.notice.controller;

import com.woniuxy.notice.pojo.Notice;
import com.woniuxy.notice.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @GetMapping("/all")
    public List<Notice> getAllNotices() {
        return noticeService.list();
    }

    @PostMapping("/add")
    public boolean addNotice(@RequestBody Notice notice) {
        return noticeService.save(notice);
    }

    @PostMapping("/updateStatus")
    public boolean updateStatus(@RequestBody Map<String, Object> params) {
        Integer id = (Integer) params.get("id");
        Integer status = (Integer) params.get("status");
        if (id == null || status == null) return false;
        Notice notice = noticeService.getById(id);
        if (notice == null) return false;
        notice.setStatus(status);
        return noticeService.updateById(notice);
    }
} 